import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { map } from 'rxjs/operators';
import { ReceivingOrder } from 'src/app/shared/domain';

@Injectable({
  providedIn: 'root',
})
export class ProductService {
  constructor(private http: HttpClient) {}
  handleGetProductDetail(id: string) {
    return this.http.get('/product-detail', {
      params: {
        id,
      },
    });
  }
  handleGetReceivingOrder() {
    return this.http.get<ReceivingOrder[]>('/product-receivingOrder').pipe(
      map(({ orderList }: any) => orderList),
      map((order) => {
        order.map((item: any) => {
          item.startAt = new Date(item.startAt);
          return item;
        });
        return order;
      })
    );
  }
}
